<div class="box box-solid no-margin box-show">
    <div class="box-body">
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th><input type="checkbox" class="grid-select-all" />&nbsp;</th>
                    <th>订单号/费用描述</th>
                    <th>国家</th>
                    <th>销售员</th>
                    <th>支付方式</th>
                    <th>支付账号</th>
                    <th>支付货币</th>
                    <th>支付金额（原币）</th>
                    <th>付款状态</th>
                    <th>付款凭证</th>
                </tr>
                </thead>
                <tbody>
                @foreach($rps as $k => $item)
                    <tr>
                        <td><input type="checkbox" class="grid-row-checkbox" data-id="{{ $item->id }}" /></td>
                        <td>{{ $item->apply->order_no ?? '' }}</td>
                        <td>{{ \App\Models\Basics\SysCountry::getCountryById($item->apply->country_id ?? '') }}</td>
                        <td>{{ \App\Util\User::getUsernameById($item->apply->seller_id ?? '') }}</td>
                        <td>{{ \App\Models\Reimburse\ReimburseApply::$_paidMethod[$item->paid_method] }}</td>
                        <td>{{ $item->paid_account_no }}</td>
                        <td>{{ $item->currency_code }}</td>
                        <td>{{ $item->paid_amount }}</td>
                        <td>{{ \App\Models\Reimburse\ReimbursePaid::$_paidStatus[$item->paid_status] }}</td>
                        <td>
                            @if(!empty($item->paid_file))
                                {!! \App\Models\Reimburse\ReimbursePaid::getImage($item->paid_file) !!}
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
</div>
<div style="margin-top: 10px;">
    <div class="box-body fields-group">
        <div class="form-group  ">
            <label class="col-sm-2  control-label"></label>
            <div class="col-sm-5">
                选择单据的支付金额汇总：<span id="paid_total" style="color: red">0.00</span>
            </div>
        </div>
    </div>
    <div class="box-body fields-group">
        <div class="form-group  ">
            <label class="col-sm-2  control-label"></label>
            <div class="col-sm-5">
                <label class="col-sm-5 control-label"></label>
                <button type="button" id="do-paid" class="btn btn-primary">上传支付凭证</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="uploadModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
            var sum = 0;
            $(".grid-row-checkbox").each(function(){
                if (this.checked) {
                    var tr = $(this).closest('tr');
                    var amount = tr.find('td').eq(7).text();
                    sum += amount ? Number(amount) : 0;
                }
            });
            $('#paid_total').text(sum.toFixed(3));
        });
        $('.grid-select-all').iCheck({checkboxClass:'icheckbox_minimal-blue'});
        $('.grid-select-all').on('ifChanged', function(event) {
            if (this.checked) {
                $('.grid-row-checkbox').iCheck('check');
            } else {
                $('.grid-row-checkbox').iCheck('uncheck');
            }
            var sum = 0;
            $(".grid-row-checkbox").each(function(){
                if (this.checked) {
                    var tr = $(this).closest('tr');
                    var amount = tr.find('td').eq(7).text();
                    sum += amount ? Number(amount) : 0;
                }
            });
            $('#paid_total').text(sum.toFixed(3));
        });

        var selectedRows = function () {
            var selected = [];
            $('.grid-row-checkbox:checked').each(function(index){
                selected.push($(this).data('id'));
            });
            return selected;
        };

        $('#do-paid').on('click', function(e) {
            e.preventDefault();
            var ids = selectedRows().join(',');
            if(!ids) {
                swal('请选择支付单据', '', 'error');
                return false;
            }
            $("#uploadModal").modal({
                remote : '/xqc/reimburse/paid-modal?action=batchPaidFile&param=' + ids
            });
        });
        $("#uploadModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });
    });
</script>
